function mask(card) {
  const showChars = card.slice(card.length - 4);
  if (card.includes('-')) return "****-****-****-" + showChars;
  else if (card.includes(' ')) return "**** **** **** " + showChars;
}


console.log(mask("4012-8888-8888-1881"));